class PlayList {
  final String songId;
  final String songName;
  final String artist;
  final String coverUrl;
  final String musicUrl;

  PlayList({
    required this.songId,
    required this.songName,
    required this.artist,
    required this.coverUrl,
    required this.musicUrl,
  });

  factory PlayList.fromJson(Map<String, dynamic> json) {
    return PlayList(
      songId: json['id']?.toString() ??
          json['link']?.toString().split('/').last ??
          '',
      songName: json['title'] ?? '未知歌曲',
      artist: json['singer'] ?? '未知歌手',
      coverUrl: json['cover'] ?? '',
      musicUrl: json['music_url'] ?? '',
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': songId,
      'title': songName,
      'singer': artist,
      'cover': coverUrl,
      'music_url': musicUrl,
    };
  }

  @override
  String toString() {
    return 'PlayList{songId: $songId, songName: $songName, artist: $artist}';
  }

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is PlayList &&
          runtimeType == other.runtimeType &&
          songId == other.songId;

  @override
  int get hashCode => songId.hashCode;
}